/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLO;

import DAO.ExamDAO;
import DTO.ExamDTO;
import Util.ConnectionUtil;
import java.sql.Connection;
import java.util.ArrayList;

/**
 *
 * @author Arturia
 */
public class ExamBLO {

    private Connection con;

    public ArrayList<ExamDTO> getAllExams() {
        ArrayList<ExamDTO> list = new ArrayList<ExamDTO>();
        try {
            con = ConnectionUtil.getConnection();
            list = ExamDAO.LoadDatabase(con, null);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public ArrayList<ExamDTO> getExamOfASubject(String subjectid){
        ArrayList<ExamDTO> list = new ArrayList<ExamDTO>();
        try{
            con = ConnectionUtil.getConnection();
            list = ExamDAO.getAllExamsOfAnSubject(con, subjectid);
        }catch(Exception e){
            e.printStackTrace();
        }
        return list;
    }

    public boolean insertExam(ExamDTO exam) {
        con = ConnectionUtil.getConnection();
        if (ExamDAO.insert(con, exam) > 0) {
            return true;
        }
        return false;
    }

    public boolean updateExam(ExamDTO exam) {
        con = ConnectionUtil.getConnection();
        if (ExamDAO.update(con, exam) > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteExam(String deleteExam) {
        con = ConnectionUtil.getConnection();
        if (ExamDAO.delete(con, deleteExam) > 0) {
            return true;
        }
        return false;
    }
}
